Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve cli #3

Merged
merged 14 commits into from
Sep 17, 2024
Merged

refactor: improve cli #3

merged 14 commits into from
Sep 17, 2024

Conversation

aarcex3
Copy link
Contributor

@aarcex3 aarcex3 commented Aug 31, 2024

Code proposal

The main cli has been refactor and a new command has been added, namely generate.
This is a proposal to generate a folder like the ones on the fullstack example, where a resource consists of a controller, service, dtos, models and a repository file.
The proposal is to follow a Nestjs like philosophy when it comes to the cli.

Related Issue

None

feat:  Add new command.
test: Update tests
@aarcex3 aarcex3 changed the title Improve cli, add new command, improve tests refactor: Improve cli Aug 31, 2024
@aarcex3 aarcex3 changed the title refactor: Improve cli refactor: improve cli Sep 3, 2024
Copy link
Owner

@ch-iv ch-iv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Thanks for the pull request, your work is really appreciated. I totally agree with having an option to generate individual resources. In addition to some of the comments that I've left, I also think that you should not use RenderingContext for rendering a resource. Instead create another context class (something like ResourceRenderingContext with resource specific context fields) and use it to render resources instead.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove IDE configuration files from the commit.

litestar project init --app-name MyProject
```

This command is used to initialize a Litestar project named MyProject in the current working directory. MyProject will have the following tree structure:

```
```bash
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason behind this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks cleaner in my opinion, I can remove it if you want

pyproject.toml Outdated
@@ -306,6 +306,7 @@ distribution = true
[tool.pdm.dev-dependencies]
dev = [
"litestar[standard,cryptography,jinja]>=2.9.1",
"black>=24.8.0",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project uses ruff for linting. Remove black dependency and lint the PR using ruff.

Comment on lines 18 to 20
@click.group(cls=LitestarGroup)
def cli():
pass
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is meant to be an extension of the LItestar's CLI, so it doesn't really make sense for the group to be named CLI. Rename this group back to project.

render_template(template_dir, output_dir, ctx, run_ruff=True)

packages_to_install = ["litestar"]
venv_name = "venv"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to make assumptions about what the virtual environment name is, nor do we want to hard code that assumption. Factor out the virtual environment name into a constant and possibly make a list of possible venv names to check against.

@aarcex3
Copy link
Contributor Author

aarcex3 commented Sep 10, 2024

Hey! Thanks for the pull request, your work is really appreciated. I totally agree with having an option to generate individual resources. In addition to some of the comments that I've left, I also think that you should not use RenderingContext for rendering a resource. Instead create another context class (something like ResourceRenderingContext with resource specific context fields) and use it to render resources instead.

Would it be ok to make a subclass of RenderingContext for this matter? Or maybe create an abstract RenderingContext from which the other can inherent? Because in most cases we just render jinja files (and others), right?

@ch-iv
Copy link
Owner

ch-iv commented Sep 11, 2024

Since RenderingContext is a dataclass it wouldn't really make sense to have another class inherit from it. RenderingContext just a structure holding some values used during rendering. I would just create another dataclass called ResourceRenderingContext without any inheritance. And maybe rename RenderingContext to AppRenderingContext.

@ch-iv
Copy link
Owner

ch-iv commented Sep 17, 2024

@aarcex3 Thank you for your efforts.

@ch-iv ch-iv merged commit 9407f90 into ch-iv:main Sep 17, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants